package wei.xinya;

import java.io.File;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.LinkedList;

public class MyFileVisitor extends SimpleFileVisitor<Path> {

    private String fileSuffix;

    private final LinkedList<File> files;

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public LinkedList<File> getFiles() {
        return files;
    }

    public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
        if (path.toString().endsWith(fileSuffix)) {
            files.add(path.toFile());
        }
        return FileVisitResult.CONTINUE;
    }

    public MyFileVisitor(String suffix) {
        fileSuffix = suffix;
        files = new LinkedList<>();
    }

}
